﻿@model iChip.Hotspots.Models.IndexObject
@{
    ViewBag.Title = "Home Page";
}

<div class="jumbotron">
    <h1>ASP.NET</h1>
    <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
    <p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more &raquo;</a></p>
</div>

<div class="row">
    <div class="col-md-4">
        <h2>Getting started</h2>
        <p>
            ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
            enables a clean separation of concerns and gives you full control over markup
            for enjoyable, agile development.
        </p>
        <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301865">Learn more &raquo;</a></p>
    </div>
    <div class="col-md-4">
        <h2>Get more libraries</h2>
        <p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
        <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more &raquo;</a></p>
    </div>
    <div class="col-md-4">
        <h2>Web Hosting</h2>
        <p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
        <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301867">Learn more &raquo;</a></p>
    </div>
</div>
<section>
    <div class="row">
        @Html.Raw(Model.Splash.Splash_Content)
    </div>
</section>
@*@using (Html.BeginForm("PostInfo", "home", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{*@ 
    <section>
        <div class="row">
            @foreach(var item in Model.Fields)
            {
                <div class="col-md-12">
                    @if(item.FieldType_Id==1) // string => textbox
                    {
                        @Html.TextBoxFor(m => item.Field_Name, new { @class = "form-control", id=@item.Field_Id });
                    }
                    else if(item.FieldType_Id==2) // textarea
                    {
                        @Html.TextAreaFor(m => item.Field_Name, new { width = " 100px ", @class = "form-control", id=@item.Field_Id })
                    }
                    else if(item.FieldType_Id==3)
                    {
                    
                    }
                </div>
            }
        </div>
    </section>
<section>
    <div class="row">
        
        <input type="button" value="Submit" onclick="PostFormData()" />
    </div>
</section>
@*}*@

<script>
    var mac = '@ViewBag.Mac';
    function PostFormData() {

        var objRequest = [];
        var objForm = $("[name='item.Field_Name']");
        if ($(objForm).length > 0) {
            
            for (var i = 0; i < $(objForm).length; i++) {
                var objItem = {};
                objItem.Id = parseInt($(objForm)[i].id);
                objItem.Value = $($(objForm)[i]).val();
                objRequest.push(objItem);
            }
        }

        console.log("ABC", JSON.stringify({ objRequest: objRequest }));
        $.ajax({
            method: "POST",
            url: "/home/PostInfo",
            data: JSON.stringify({ objRequest: objRequest, mac: mac }),
            contentType: "application/json",
        })
          .done(function (msg) {
              //alert("Data Saved: " + msg);
          });
    }
</script>